package com.example.gslih.myapplication.system;

import java.io.File;
import java.io.FileFilter;

/**
 * Create by Gene : 2018/12/19  16:05
 */
public class TtCpuCoreNumber {

    //获取cpu核心数
    public int getCpuCoresNum(){
        return new File("/sys/devices/system/cpu/").listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                String path = pathname.getName();
                if (path.startsWith("cpu")) {
                    for (int i = 3; i < path.length(); i++) {
                        int tab = Integer.getInteger(String.valueOf(path.charAt(i)));
                        if (tab < 0 || tab > 12) {
                            return false;
                        }
                    }
                    return true;
                }
                return false;
            }
        }).length;
    }
}
